import {
  FetchGetLogin,
  FetchUserInfo,
  FetchGetRegister,
  FetchQueryUsers,
  FetchUpdateUsers,
  FetchDeleteUsers
} from '../api/index'
const users = {
  //  namespaced: 'users',
  state: {
    token: '',
    useInfo: {}
  },
  mutations: { // 处理逻辑
    SET_TOKEN(state, token) {
      state.token = token;
    },
    SET_USER_INFO(state, userInfo) {
      state.useInfo = userInfo;
    }
  },
  actions: { // 处理异步代码的 http请求
    GetLogin({ commit }, { username, password }) {
      return new Promise((resolve, reject) => {
        FetchGetLogin({ username, password }).then(res => {
          // commit
          // resolve
          commit('SET_TOKEN', res.data.token)
          localStorage.setItem('token', res.data.token)
          // 及时将结果通知组件，我已经请求结束了；
          resolve({code: 0, msg: '登陆成功', data: res.data})
        })
      })
    },
    GetUserInfo({ commit }, data) {
      return new Promise((resolve, reject) => {

      })
    },
    GetQueryUsers({ commit }, { page, size}) {
      return new Promise((resolve, reject) => {
        FetchQueryUsers({page, size}).then(res => {
          // 及时将结果通知组件，我已经请求结束了；
          resolve({code: 0, msg: '查询成功', data: res.data})

        })
      })
    }

  },
  getters: {}
}

export default users;
